﻿package mortal.game.view.LineOffReward.panel
{
    import com.gengine.resource.*;
    import com.mui.controls.*;
    import flash.events.*;
    import flash.text.*;
    import mortal.common.global.*;
    import mortal.component.gconst.*;
    import mortal.game.cache.*;
    import mortal.game.events.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.display.*;
    import mortal.game.view.nationalDayAct.*;
    import mortal.game.view.signUp.view.*;
    import mortal.game.view.vip.*;
    import mortal.mvc.core.*;

    public class LineOffRewardExpPanel extends SignUpViewBase
    {
        protected var _bgMM:GImageBitmap;
        protected var _num1:BitmapNumberText;
        protected var _num2:BitmapNumberText;
        protected var _doubleT:GBitmap;
        protected var _comBtn:GLoadingButton;
        protected var _vipBtn:GLoadingButton;
        protected var _curV:GTextFiled;
        protected var _nextV:GTextFiled;
        protected var _getBackBtn:GLoadingButton;
        protected var _getBtnDes:GBitmap;
        protected var _timeTxt:GTextFiled;
        protected var _expTxt:GTextFiled;
        private var _vipType:int = 32;
        public var uiLoadComplete:Boolean = false;

        public function LineOffRewardExpPanel()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            LoaderHelp.addResCallBack(ResFileConst.LineOffReward, this.onResLoad);
            return;
        }// end function

        private function setNationalDayActStyle(param1:Object = null) : void
        {
            if (!this._bgMM)
            {
                return;
            }
            if (nationalDayActUtil.checkDate() && nationalDayActUtil.getLeftTime(nationalDayActConst.Act_LineOff) > 0)
            {
                this._bgMM.imgUrl = ImagesConst.lineOffExpBgNationalDayStlye;
            }
            else
            {
                this._bgMM.imgUrl = ImagesConst.lineOffExpBg;
            }
            return;
        }// end function

        private function onResLoad() : void
        {
            var _loc_1:TextFormat = null;
            this.uiLoadComplete = true;
            if (this.isDisposed)
            {
                return;
            }
            this._bgMM = UIFactory.gImageBitmap("", 0, 0, this);
            this.setNationalDayActStyle();
            this._num1 = UIFactory.bitmapNumberText(119, 447, "PetGrowPurpleNum.png", 22, 32, -7, this, 9, 1);
            this._num1.text = "123456";
            this._num2 = UIFactory.bitmapNumberText(319, 447, "PetGrowPurpleNum.png", 22, 32, -7, this, 9, 1);
            this._num2.text = "12346798";
            this._doubleT = UIFactory.gBitmap(ImagesConst.LineOffExpDouble, 372, 447);
            this._comBtn = UIFactory.gLoadingButton(ImagesConst.LineOffComBtn_upSkin, 423, 459, 127, 44);
            this._comBtn.label = "";
            this._vipBtn = UIFactory.gLoadingButton(ImagesConst.LineOffVIPBtn_upSkin, 555, 459, 127, 44);
            this._vipBtn.label = "";
            this._curV = UIFactory.gTextField("VIP0", 81, 399, 56, 25, this, GlobalStyle.textFormatHuang2.setSize(15).center().setBold(true));
            this._nextV = UIFactory.gTextField("VIP1", 278, 399, 56, 20, this, GlobalStyle.textFormatHuang2.setSize(15).center().setBold(true));
            this._getBackBtn = UIFactory.gLoadingButton(ImagesConst.LineOffBtn_upSkin, 471, 465, 117, 44, this);
            this._getBackBtn.label = "";
            this._getBtnDes = UIFactory.gBitmap(ImagesConst.LineOff, 497, 477, this);
            this._comBtn.configEventListener(MouseEvent.CLICK, this.onGetExpHd);
            this._vipBtn.configEventListener(MouseEvent.CLICK, this.onGetExpHd);
            this._getBackBtn.configEventListener(MouseEvent.CLICK, this.onGetExpHd);
            this._timeTxt = UIFactory.gTextField("02:20:56", 181, 237, 200, 25, this);
            this._expTxt = UIFactory.gTextField("456789", 182, 267, 200, 25, this);
            if (GameController.signUp.lineOffFirstReqData)
            {
                GameController.signUp.lineOffFirstReqData = false;
                Dispatcher.dispatchEvent(new DataEvent(EventName.LineOffRewardOnOpenPage));
            }
            else
            {
                this.updateExp();
            }
            _loc_1 = GlobalStyle.textFormatLv;
            _loc_1.size = 15;
            _loc_1.bold = true;
            this._timeTxt.defaultTextFormat = _loc_1;
            this._timeTxt.setTextFormat(_loc_1);
            this._expTxt.defaultTextFormat = _loc_1;
            this._expTxt.setTextFormat(_loc_1);
            Dispatcher.addEventListener(ServerCommand.NewDayUpdate, this.setNationalDayActStyle);
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            if (this.uiLoadComplete == false)
            {
                return;
            }
            this._bgMM = null;
            this._num1 = null;
            this._num2 = null;
            this._doubleT = null;
            this._comBtn = null;
            this._vipBtn = null;
            this._curV = null;
            this._nextV = null;
            this._getBackBtn = null;
            this._getBtnDes = null;
            this._timeTxt = null;
            this._expTxt = null;
            return;
        }// end function

        public function updateExp() : void
        {
            if (Cache.instance.lineOff.lineOffInfo == null)
            {
                return;
            }
            this.updateLineOffTime();
            this.updateExpTxt();
            this.updateBtn();
            return;
        }// end function

        private function updateLineOffTime() : void
        {
            var _loc_1:* = Cache.instance.lineOff.lineOffInfo.offlineTime;
            var _loc_2:* = _loc_1 / 3600;
            var _loc_3:* = _loc_1 / 60 % 60;
            var _loc_4:int = 0;
            var _loc_5:String = "";
            _loc_5 = _loc_5 + (this.getNumStr(_loc_2) + ":");
            _loc_5 = _loc_5 + (this.getNumStr(_loc_3) + ":");
            _loc_5 = _loc_5 + this.getNumStr(_loc_4);
            this._timeTxt.text = _loc_5;
            return;
        }// end function

        private function getNumStr(param1:int) : String
        {
            if (param1 >= 10)
            {
                return "" + param1;
            }
            return "0" + param1;
        }// end function

        private function updateExpTxt() : void
        {
            var _loc_4:Number = NaN;
            var _loc_5:int = 0;
            var _loc_1:* = Cache.instance.vip.level;
            var _loc_2:* = Number(VipConfig.instance.getValueByTypeAndLv(this._vipType, _loc_1));
            var _loc_3:* = VipUtil.getVipMinLevelByType(this._vipType);
            var _loc_6:Boolean = false;
            if (_loc_2 == 0)
            {
                _loc_2 = 100;
            }
            _loc_5 = _loc_1;
            while (_loc_5 < 20)
            {
                
                if (_loc_2 == 100)
                {
                    _loc_2 = 100;
                    _loc_5 = _loc_1 + 1;
                    _loc_4 = Number(VipConfig.instance.getValueByTypeAndLv(this._vipType, _loc_5));
                    break;
                }
                _loc_4 = Number(VipConfig.instance.getValueByTypeAndLv(this._vipType, _loc_5));
                if (_loc_4 == 0)
                {
                    _loc_4 = _loc_2;
                    _loc_6 = true;
                    break;
                }
                else if (_loc_4 != _loc_2)
                {
                    break;
                }
                _loc_5++;
            }
            var _loc_7:* = Cache.instance.lineOff.expData;
            var _loc_8:* = _loc_7 * _loc_4 / 100;
            _loc_7 = _loc_7 * _loc_2 / 100;
            this._expTxt.text = "" + _loc_7;
            this._num1.text = "" + _loc_7;
            this._num2.text = "" + _loc_8;
            this._curV.text = "VIP" + _loc_1;
            this._nextV.text = "VIP" + (_loc_6 ? (_loc_1) : (_loc_5));
            return;
        }// end function

        private function updateBtn() : void
        {
            var _loc_1:int = 0;
            if (Cache.instance.lineOff.expData == 0)
            {
                this.enBtn(this._comBtn, false);
                this.enBtn(this._vipBtn, false);
                this.enBtn(this._getBackBtn, false);
            }
            else
            {
                this.enBtn(this._getBackBtn, true);
                _loc_1 = Cache.instance.vip.level;
                if (VipUtil.isVipReachLevelByType(32) == false)
                {
                    this.enBtn(this._comBtn, true);
                    this.enBtn(this._vipBtn, false);
                }
                else
                {
                    this.enBtn(this._comBtn, false);
                    this.enBtn(this._vipBtn, true);
                }
            }
            return;
        }// end function

        private function enBtn(param1:GLoadingButton, param2:Boolean) : void
        {
            if (param1 == null)
            {
                return;
            }
            param1.enabled = param2;
            if (param2)
            {
                param1.filters = null;
            }
            else
            {
                param1.filters = [FilterConst.colorFilter2];
            }
            return;
        }// end function

        private function onGetExpHd(event:MouseEvent) : void
        {
            var _loc_2:int = 1;
            if (this._vipBtn == event.currentTarget)
            {
                _loc_2 = 2;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.LineOffRewardGetExp, _loc_2));
            return;
        }// end function

    }
}
